package pers.zcr.meringue.monolithic.system.captcha.web;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.zcr.meringue.monolithic.system.captcha.dto.vo.CaptchaVo;
import pers.zcr.meringue.monolithic.system.captcha.service.ICaptchaService;
import pers.zcr.meringue.monolithic.system.captcha.web.dtoadapter.CaptchaVoAdapter;

/**
 * 验证码操作处理
 *
 * @author Lion Li
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@Tag(name = "验证码")
public class CaptchaController {

    private ICaptchaService captchaService;

    @Autowired
    public CaptchaController(ICaptchaService captchaService) {
        this.captchaService = captchaService;
    }

    /**
     * 生成验证码
     */
    @Operation(summary = "生成验证码", description = "生成验证码")
    @GetMapping("/auth/code")
    public CaptchaVoAdapter getCode() {
        CaptchaVo captchaVo = captchaService.generateCode();
        return BeanUtil.copyProperties(captchaVo, CaptchaVoAdapter.class);
    }

}
